<template>
    <vol-box :lazy="true" v-model="model" title="选择产品" :width="1200" :padding="0">
        <div>
            <material ref="materialRef"></material>
        </div>
        <template #footer>
            <div> <el-button type="primary" @click="onSelect">确认</el-button></div>
        </template>
    </vol-box>
</template>
<script setup>
import { ref, getCurrentInstance, nextTick } from 'vue'
const { proxy } = getCurrentInstance();
/******注意：如果出现提示没有权限的问题，见后台开发文档上的【重写后台权限】*****/
//直接引用生成的页面(也可以单独用table配置，单独配置下见下面【编辑弹出框明细表选择数据】)
import material from '@/views/mes/mes/Material.vue';
const materialRef = ref();
const model = ref(false)
//回调
const emit = defineEmits('onSelectMaterial')
const open = () => {
    //打开主表选择数据
    model.value = true;
    //打开时刷新界面数据
    nextTick(() => {

        console.log(materialRef.value.$refs.grid)
        //选择弹窗设置默认条件，已审核AuditStatus = 1，启用IsEnabled = 1

        materialRef.value.$refs.grid.searchFormFields.AuditStatus = 1
        materialRef.value.$refs.grid.searchFormFields.IsEnabled = 1
        materialRef.value?.$refs.grid?.search()
    });
}
//选择数据
const onSelect = () => {
    //主表的选择数据回写到主表的表单上
    let rows = materialRef.value.$refs.grid.getSelectRows();
    if (!rows.length) {
        return proxy.$message.error('请选择数据');
    }


    model.value = false;
    emit('onSelectMaterial', rows)
}
//暴露选择弹出框方法
defineExpose({ open })
</script>
<style lang="less" scoped>
.search-form {
    display: flex;
    padding: 10px;
    line-height: 34px;

    button {
        margin-left: 10px;
    }
}
</style>